package binarycrew.livewallpapers;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import binarycrew.livewallpapers.utils.PreferenceHelper;

public class SettingsActivity extends PreferenceActivity
		implements SharedPreferences.OnSharedPreferenceChangeListener {

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		getPreferenceManager().setSharedPreferencesName(
				Preferences.SHARED_PREFS_NAME);
		addPreferencesFromResource(R.xml.settings);
		getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
				this);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
				this);
		super.onDestroy();
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
		if (key.equals(getResources().getString(R.string.sme_press_foto_key))) {
			PreferenceHelper.adjustSourceUrlsByKey(
					getResources().getString(R.string.sme_press_foto_key),
					getResources().getString(R.string.sme_press_foto_url),
					sharedPreferences);
		}

		if (key.equals(getResources().getString(R.string.sme_futbal_foto_key))) {
			PreferenceHelper.adjustSourceUrlsByKey(
					getResources().getString(R.string.sme_futbal_foto_key),
					getResources().getString(R.string.sme_futbal_foto_url),
					sharedPreferences);
		}

	}
}
